package com.course.app.transformer;

import com.course.app.api.data.TaskAudioDTO;
import com.course.domain.model.TaskAudio;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Created by Justin on 2017/5/30.
 */
public class TaskAudioTransformer {

    public static Map<Integer, TaskAudioDTO> toAudioMap(List<TaskAudio> taskAudioList) {
        return taskAudioList.stream()
                .map(TaskAudioTransformer::toAudio)
                .collect(Collectors.toMap(TaskAudioDTO::getId, Function.identity()));
    }

    private static TaskAudioDTO toAudio(TaskAudio taskAudio) {
        TaskAudioDTO audioDTO = new TaskAudioDTO();
        audioDTO.setId(taskAudio.getId());
        audioDTO.setTitle(taskAudio.getTitle());
        audioDTO.setDetail(taskAudio.getDetail());
        audioDTO.setMediaLink(taskAudio.getAudioLink());
        audioDTO.setAlbumLink(taskAudio.getAlbumLink());
        audioDTO.setRepeatTimes(taskAudio.getTimes());
        audioDTO.setSpeed(taskAudio.getSpeed());
        return audioDTO;
    }
}
